package com.dbb.util;

import java.io.Serializable;

import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.UUIDHexGenerator;

public class UIDGenerator extends UUIDHexGenerator {

	@Override
	public Serializable generate(SessionImplementor session, Object object) {
		return new StringBuilder(16).append(formatShort(getAppId())).append(format(getHiTime())).append(
				format(getLoTime())).append(formatShort(getCount())).toString();
	}

	protected short getAppId() {
		return 0;
	}

	protected String formatShort(short value) {
		String formatted = Integer.toHexString(value);
		if (formatted.length() < 2) {
			formatted = "0" + formatted;
		}
		return formatted;
	}
}
